<template>
	<view class="container">
		<view class="header-tabs">
			<view class="tab-item" :class="{active:current==0}" :data-current="0" @tap="current = 0">
				<text class="text">
					邀请记录
				</text>
			</view>
			<view class="tab-item" :class="{active:current==1}" :data-current="1" @tap="current = 1">
				<text class="text">
					分销订单
				</text>
			</view>
		</view>

		<view class="swiper-wrapper">
			<swiper :current="current" @change="swiperChange">
				<swiper-item>
					<scroll-view scroll-y @scrolltolower="scrolltolower">
						<UserItem :info="item" v-for="(item, index) in userList"></UserItem>
						<view style="height: 90vh;overflow: hidden;" v-if="!userList.length">
							<NoData></NoData>
						</view>

					</scroll-view>
				</swiper-item>
				<swiper-item>
					<scroll-view scroll-y @scrolltolower="scrolltolower">
						<!-- :info="item" v-for="(item, index) in orderList" :key="index" -->
						<AgentRecordItem :info="orderList"></AgentRecordItem>
						<view style="height: 90vh;overflow: hidden;" v-if="!orderList.length">
							<NoData v-if="!orderList.length"></NoData>
						</view>

					</scroll-view>
				</swiper-item>
			</swiper>
		</view>

		<view class="footer-c  safe-area-bottom">
			<view class="btn-c">
				<!-- check-rule -->
				<navigator class="btn" url="/pages/rule/index?type=share">
					<button class="btn ">查看分销规则</button>
				</navigator>
				<navigator class="btn" url="/pages/rule/rule/rule?id=9">
					<button class="btn ">邀请好友规则</button>
				</navigator>
			</view>
		</view>

	</view>
</template>

<script>
	import UserItem from "./components/UserItem"
	import AgentRecordItem from "./components/AgentRecordItem"
	export default {
		components: {
			UserItem,
			AgentRecordItem
		},
		data() {
			return {
				current: 0,
				userList: [],
				orderList: [],
				// total: 0,
				page: 1,
				per_page: 20,
				// init: false,
				// loading: false
			}
		},
		computed: {},
		async onLoad(e) {
			this.current = e.actived || 0

			uni.showLoading({
				title: '加载中'
			})

			this.initData()

			uni.hideLoading()
		},
		onShow() {
			// this.initData()
		},
		methods: {
			initData() {
				this.$http('/invite-records/findInvitationRecord', 'get', {
					pageSize: this.per_page,
					currentPage: this.page,
					// type: 'direct'
				}).then(res => {
					this.userList = res.data.list
				})

				this.$http({
					url: '/brokerage-records/find',
					method: 'get',
					params: {
						pageSize: this.per_page,
						currentPage: this.page
					}
				}).then(res => {
					this.orderList = res.data.list
				})
			},
			fetchNextPage() {
				if (this.loading) {
					return false
				}
				this.loading = true
				this.page++
				this.$http('/user/invitees', 'get', {
					per_page: this.per_page,
					page: this.page,
					type: 'direct'
				}).then(res => {
					this.userList = this.userList.concat(res.data.list)

					this.loading = false
				})
			},
			swiperChange(e) {
				let index = e.detail.current
				this.current = index
			},
			scrolltolower() {
				this.fetchNextPage()
			}
		}
	}
</script>
<style>
	page {
		background: url(../../static/bgColor.png) center/ cover no-repeat;
	}
</style>
<style lang="scss" scoped>
	.container {}

	.header-tabs {
		width: 100%;
		display: flex;
		align-items: center;
		position: fixed;
		top: 50rpx;
		left: 0;
		z-index: 10;

		.tab-item {
			flex: 1;
			// line-height: 200rpx;
			text-align: center;
			font-size: 33rpx;
			color: #FFF;
			font-weight: 100;

			&.active {
				color: #fff;
				position: relative;

				.text {
					border-bottom: 6rpx solid rgb(232, 117, 148);
					font-weight: 100;
					padding: 0rpx 0rpx 10rpx 0rpx;
				}

				// &::after {
				// 	content: "";
				// 	position: absolute;
				// 	height: 2px;
				// 	left: 20rpx;
				// 	right: 20rpx;
				// 	bottom: 0;
				// 	background-color: #0E151D;
				// }
			}
		}
	}

	.list {}

	swiper {
		height: 100vh;
		padding-top: 100rpx;
		box-sizing: border-box;
		position: fixed;
		width: 100%;
		top: 0rpx;
		left: 0rpx;

		swiper-item {
			height: 100%;
		}

		scroll-view {
			height: 100%;
			// border: 1px solid red;
		}
	}

	.footer-c {
		position: fixed;
		bottom: 0rpx;
		width: 100%;
		left: 0rpx;

		.btn-c {
			display: flex;
			justify-content: space-between;
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx 60rpx 20rpx 60rpx;
			// background-color: #151515;
		}

		.btn {
			// width: 640rpx;
			height: 78rpx;
			color: #fff;
			background: url(../../static/seach.png) center/ cover no-repeat;
			font-weight: bold;
			text-align: center;
			line-height: 78rpx;
			font-size: 28rpx;
			border-radius: 15rpx;
			margin: 0rpx;

			&:after {
				display: none;
			}

			&.check-rule {
				color: #fff;
				background: url(../../static/seach.png) center/ cover no-repeat;
			}
		}

	}
</style>